<?php

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Colored Table
 * @author Nicola Asuni
 * @since 2008-03-04
 */

// Include the main TCPDF library (search for installation path).
require_once('tcpdf/tcpdf.php');

// extend TCPF with custom functions
class MYPDF extends TCPDF {

	
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Grupo Analisis y desarrollo de sistemas 299779');
$pdf->SetTitle('Reporte de usuarios registrados');
$pdf->SetSubject('SAVING');
$pdf->SetKeywords('usuarios, lista, clem, reporte');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, "SERVICIO NACIONAL DE APRENDIZAJE - SENA", "Centro Latinoamericano de Especies Menores - CLEM\nRegional Valle\nGenerado por SAVING\nFecha: ".date("d-m-Y"));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 11);

// add a page
$pdf->AddPage();

// data loading
include("../../BD/ConexionBDSaving.php");
$link =ConexionBDSaving::conectar();
$queEmp = "select cedulaUsuario, nombreU, apellidoU, emailU, telefonoU, nombre from usuario, perfil where usuario.nroPerfil=perfil.nroPerfil;";
$resEmp = ConexionBDSaving::consultarTodo($link, $queEmp);
$totEmp = ConexionBDSaving::extraerNumeroRegistros($resEmp);

$ixx = 0;
$i=0;
$html="";
			
$html=$html.'<div align="center">
            <br>
			Lista de usuarios registrados en SAVING
			<br /><br />			
			<table>
			<tr bgcolor="#009900">
				<td><font color="#FFFFFF">Cédula</font></td>
				<td><font color="#FFFFFF">Nombres</font></td>
				<td><font color="#FFFFFF">Apellidos</font></td>
				<td><font color="#FFFFFF">e-mail</font></td>
				<td><font color="#FFFFFF">Teléfono</font></td>
				<td><font color="#FFFFFF">Tipo de usuario</font></td>
			</tr>';	

while($datatmp = ConexionBDSaving::extraerFila($resEmp)) 
{ 
	$ixx = $ixx+1;
	$data[] = $datatmp;
	
			if($i%2==0)
			{
				$html= $html.'<tr bgcolor="#CCCCCC">';
			}else{
				$html=$html.'<tr>';
			}
			
			$html = $html.'<td>';
			$html = $html. $datatmp["cedulaUsuario"];
			$html = $html.'</td><td>';
			$html = $html. $datatmp["nombreU"];
			$html = $html.'</td><td>';
			$html = $html. $datatmp["apellidoU"];
			$html = $html.'</td><td>';
			$html = $html. $datatmp["emailU"];
			$html = $html.'</td><td>';
			$html = $html. $datatmp["telefonoU"];
			$html = $html.'</td><td>';	
			$html = $html. $datatmp["nombre"];
			$html = $html.'</td></tr>';				
			$i++;
}

$html=$html.'</table></div>';

// print colored table
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

// ---------------------------------------------------------

// close and output PDF document
ob_end_clean();
$pdf->Output('lista usuarios .pdf', 'I');

//============================================================+
// END OF FILE
//============================================================+
